/**
 * Created by coolxu on 2017/12/6.
 */
    //side.jsp,获取运维人员的信息
    var operatorside = angular.module('operatorside', []);
    operatorside.controller('operatorsidegetinfo', function ($scope, $http) {
    $scope.operatorinfo = {
        userAccount: "1506101034",
        userPhone: null,
        userType: null,//运维人员身份需区别是教师还是学生,下面才好判断是否可以修改电话号码
        userName:null
    };
    $http({
        method: 'POST',
        url: 'http://119.29.0.217:8080/sctu_it_operation_platform/getUserInfo',
        data:{"userAccount":$scope.operatorinfo.userAccount} //用户account？？？从哪里获取？从登陆获取？
    }).then(
        function successback(data) {
            $scope.operatorinfo = data.data.data;
            console.log(data);
        },
        function errorback() {
            console.log("fail");
            jError("获取信息失败，请重试！", {
                VerticalPosition: 'center',
                HorizontalPosition: 'center'
            });
        }
    );

    <!--点击修改信息，判断用户类型，如果是教师，则不允许修改电话，如果是学生则允许修改-->
        var alter_mask = document.getElementById("alter_mask");
    $scope.isshow = function (count) {
        console.log(count);
        if (count == 0) {
            //如果是教师，则不允许修改电话
            alter_mask.style.display = "none";
            alert("不允许修改，请移步教务系统！");
        } else if (count == 1) {
            //如果是学生则允许修改
            alter_mask.style.display = "block";
        }
    };
    //点击修改，修改运维人员电话
    $scope.changephone = function () {
        $scope.operinfo={
            userAccount:'1506101056',
            userName:$scope.operatorinfo.userName,
            userPassword:'654321',
            userAddress:'龙庭大酒店',
            userPhone:$scope.operatorinfo.userPhone,
            userType:0
        };
        $http({
            method: 'POST',
            url: 'http://119.29.0.217:8080/sctu_it_operation_platform/updateUserInfo',
            data: $scope.operinfo
        }).then(
            function successback() {
                jSuccess("修改电话成功！", {
                    VerticalPosition: 'center',
                    HorizontalPosition: 'center'
                });
                alter_mask.style.display = "none";
            },
            function errorback() {
                console.log("fail");
                jError("修改电话失败,请稍后重试！", {
                    VerticalPosition: 'center',
                    HorizontalPosition: 'center'
                })
            }
        )
    };
    $scope.cancelchangephone = function () {
        //点击取消按钮，取消修改电话号码的操作
        var alter_mask = document.getElementById("alter_mask");
        alter_mask.style.display = "none";
    };


        //获取服务电话
        $http({
            method: 'GET',
            url: 'http://119.29.0.217:8080/sctu_it_operation_platform/webServiceInfo'
        }).then(
            function successback(data) {
                $scope.servicephone=data.data.data.content;
            },
            function errorback() {
                console.log("fail");
                jError("获取服务电话失败,请重试！", {
                    VerticalPosition: 'center',
                    HorizontalPosition: 'center'
                })
            }
        );

        //退出登录
        $scope.logout=function(){
            window.self.location = "/logout";
        }

    });
    //notResolve.jsp,未解决的工单
    var notResolveApp = angular.module('notresolve', []);
    notResolveApp.controller('notresolveCtrl', function ($scope, $http) {
    $scope.questions={
        jobnumber:null,
        uploadTime:null,
        details:null
    };
    $http({
        method: 'POST',
        url: 'http://119.29.0.217:8080/sctu_it_operation_platform/isOngoingTasks',
        data: {'receiveOne':'1506101032','status':0}
    }).then(
        function successback(data) {
            $scope.questions = data.data.data;
            console.log(data);
        },
        function errorback() {
            console.log("fail");
            jError("获取未解决的工单失败，请重试！", {
                VerticalPosition: 'center',
                HorizontalPosition: 'center'
            })
        }
    );
    //	点击甩单，进入在线运维人员的列表页
    $scope.gooperatorslist = function (jobnum,receiveone) {//将本工单号传给在线运维人员页面
        window.self.location = "/onlinePersonnel/"+jobnum+"/"+receiveone;
    };
    //点击工单故障进入工单详情页，并将工单号传给下一页
    $scope.gomessagedetail = function (jobnum) {
        window.self.location = "/detail/"+jobnum;
    }
    });


    //message_detail.jsp,工单详情页
    var myapp = angular.module('messagedetail', []);
    myapp.controller('messagedetailCtrl', function ($scope, $http, $filter) {
        //取到上一个页面传来的工单号
    var ppp = document.getElementById("ppp").innerHTML;
    $scope.ordersinfo = {
        userAccount:null,
        uploadTime: null,
        address: null,
        details: null
    };
    $http({
        method: 'POST',
        url: 'http://119.29.0.217:8080/sctu_it_operation_platform/getWorkOrderInfo',
        data: {"jobnumber":ppp}
    }).then(
        function successback(data) {
            $scope.ordersinfo = data.data.data;
            console.log(data);
            //请求工单详情成功，再通过返回的学号，获取姓名与电话
            $scope.userinfoAccount=$scope.ordersinfo.userAccount;
            console.log($scope.userinfoAccount);
            $scope.userinfo={
                userName:null,
                userPhone:null
            };
            $http({
                method: 'POST',
                url: 'http://119.29.0.217:8080/sctu_it_operation_platform/getUserInfo',
                data: {"userAccount":$scope.userinfoAccount}
            }).then(
                function successback(data) {
                    $scope.userinfo = data.data.data;
                    //console.log(data);
                }, function errorback(res) {
                    console.log("fail");
                    jError("获取用户信息失败，请重试！", {
                        VerticalPosition: 'center',
                        HorizontalPosition: 'center'
                    })
                });


            //计算时间
            var YMD = $filter('date')($scope.ordersinfo.uploadTime, 'yyyy/MM/dd:hh:mm:ss');
            console.log('uploadtime-----' + $scope.ordersinfo.uploadTime);
            console.log("ymd------" + YMD);

            $scope.SetTimer = function () {
                //angularJs获取创建工单时间，与现在的时间进行计算
                $scope.$apply(function () {
                    var now = new Date();
                    var endmonth = now.getMonth() + 1;
                    $scope.Now = now.getFullYear() + '/' + endmonth + '/' + now.getDate() + ':' + now.getHours() + ':' + now.getMinutes();
                    var startyear = YMD.substring(0, 4);
                    var endyear = now.getFullYear();
                    var startmonth = YMD.substring(5, 7);
                    var startdate = YMD.substring(8, 10);
                    var enddate = now.getDate();
                    var starthour = YMD.substring(11, 13);
                    var endhour = now.getHours();
                    var startmin = YMD.substring(14, 16);
                    var endmin = now.getMinutes();
                    //          console.log("startyear-------" + startyear + "startmonth----" + startmonth + "startdate----" + startdate + "starthour----" + starthour + "startmin----" + startmin);
                    //          console.log("endyear------" + endyear + "endmonth---" + endmonth + "enddate----" + enddate + "endhour----" + starthour + "endmin----" + endmin);

                    if (endyear < startyear) {
                        //                如果现在的时间小于创建时间，说明发生错误，直接返回
                        $scope.Now = "发生错误";
                        return;

                    }
                    else if (endyear == startyear) {
                        //如果现在时间与创建工单时间是同一年，则判断月份
                        if (endmonth < startmonth) {
                            //如果现在月份小于创建月份，则说明发生错误，直接返回
                            $scope.Now = "发生错误";
                            return;
                        } else if (endmonth == startmonth) {
                            //如果是同一个月，则对天进行判断
                            if (enddate - startdate > 1) {
                                //如果现在时间大于创建时间一天，则直接显示大于一天
                                $scope.Now = "大于一天";
                            } else {
                                //否则则使用现在时间减去创建时间
                                $scope.Now = endhour - starthour + "小时";
                            }
                        } else if (endmonth - startmonth >= 1) {
                            //如果现在月份减去创建月份大于一月，则显示大于一月
                            $scope.Now = "大于一月";
                        }

                    } else if (endyear - startyear >= 1) {
                        //如果现在年份减去创建年份大于等于一，则显示大于一年
                        $scope.Now = "大于一年";
                    }
                });

            };
            //隔三分钟刷新一次
            $scope.SetTimerInterval = setInterval($scope.SetTimer, 30000);


        }, function errorback(res) {
            console.log("fail");
            jError("获取详情失败，请重试！", {
                VerticalPosition: 'center',
                HorizontalPosition: 'center'
            })
        });

//time--------------------------------------------


    });

    //history.jsp历史工单页面
    var historyapp = angular.module('historyapp', []);
    historyapp.controller('historyCtrl', function ($scope, $http) {
    $scope.historyinfo = {
        details: null,
        uploadTime: null,
        jobnumber: null,
        receiveOne:'1506101032'
    };
    $http({
        method: 'POST',
        url: 'http://119.29.0.217:8080/sctu_it_operation_platform/isOngoingTasks',
        data: {"receiveOne": $scope.historyinfo.receiveOne,"status":1}
    }).then(
        function successback(data) {
            $scope.historyinfo = data.data.data;
            console.log(data.data);
        }, function errorback(res) {
            console.log(res);
            jError("查看历史工单失败，请重试！", {
                VerticalPosition: 'center',
                HorizontalPosition: 'center'
            });
        });

        $scope.openDetail=function(jobnum){
            window.self.location="/detail/"+jobnum;
        }
        });


    //go_operators.jsp，获取可甩单的运维人员列表
    var goOperatorApp = angular.module('goOperatorApp', []);
    goOperatorApp.controller('goOperatorCtrl', function ($scope, $http) {
        //获取上一个页面传来的工单号和工号
        var receiveonep = document.getElementById("receiveonep").innerHTML;
        var jobnumberp = document.getElementById("jobnumberp").innerHTML;

    $http({
        method: 'GET',
        url: 'http://119.29.0.217:8080/sctu_it_operation_platform/isOnline'
    }).then(
        function successback(data) {
            $scope.operinfo = data.data.data;
            console.log(data);
        }, function errorback() {
            console.log("fail");
            jError("获取在线运维人员列表失败，请重试！", {
                VerticalPosition: 'center',
                HorizontalPosition: 'center'
            })
        });
    $scope.go = function () {
    //console.log("工单号是"+receiveonep+"工号是"+jobnumberp);

        $scope.pro = prompt("确定甩单请填写理由：", "");
    //					console.log($scope.pro);
        $http({
            method: 'POST',
            url: 'http://119.29.0.217:8080/sctu_it_operation_platform/throwWorkOrder',
            data: {jobnumber:jobnumberp,receiveOne:$scope.operinfo.userAccount,receiveTwo:receiveonep}
        }).then(
            function successback() {
                jSuccess("甩单成功！", {
                    VerticalPosition: 'center',
                    HorizontalPosition: 'center'
                })
            }, function errorback() {
                console.log('fail');
                jError("甩单失败，请重试！", {
                    VerticalPosition: 'center',
                    HorizontalPosition: 'center'
                })
            }
        )
    }
    });


